Skip to content

Comments

Homework5 task1#3

Open
shannami wants to merge 20 commits intomainfrom
homework5Task1
Open

Homework5 task1#3
shannami wants to merge 20 commits intomainfrom
homework5Task1

Conversation

@shannami
Copy link
Owner

Шалахина Анна дз 5.1

@shannami shannami requested a review from WoWaster October 16, 2025 16:52
Comment on lines 6 to 9




Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем столько?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump

Comment on lines +2 to +11
#include <stdlib.h>

struct StackNode {
int value;
struct StackNode* next;
};

struct Stack {
struct StackNode* head;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется, Вы не очень разобрались в системе модулей. Модуль состоит из заголовочного файла (.h) и файла с реализацией (.c). В заголовочном файле описывается "интерфейс" модуля, то есть функции и типы, которые можно использовать извне. Чтобы избегать дублирования и ошибок, связанных с разными типами с одним названием, заголовочные файлы требуется обязательно include в файл с реализацией. У Вас не так, поэтому есть дублирование.

Comment on lines 3 to 10
struct StackNode {
int value;
struct StackNode* next;
};

struct Stack {
struct StackNode* head;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай

  1. сделаем это настоящим АТД, чтобы пользователь не мог залезть в реализацию
  2. сделаем typedef, чтобы слово struct можно было не писать

Comment on lines 12 to 15
struct Stack new(void);
void push(struct Stack* stack, int value);
int pop(struct Stack* stack);
int isEmpty(struct Stack* stack);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

К функциям требовалось писать комментарии о том, что они делают!

Comment on lines 32 to 34
if (stack->head == NULL) {
return 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот это ой какое плохое решение --- у Вас ошибка на самом деле лежит в области допустимых значений структуры. Вам нужно или использовать errorCode/outValue, или перелоджить отвественность на пользователя, заставив его вызывать isEmpty всегда, когда он пытается вызывать pop. И любое из решений необходимо задокументировать.

int isEmpty(struct Stack* stack)
{
return stack->head == NULL;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хорошо бы ещё уметь удалять стек

#include "stack.h"
#include <stdio.h>

int isBalanced(char* s)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А почему не bool?

}

int res = isEmpty(&st);
return res;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Содержательно правда, но вот память течёт. Это нужно исправить. При этом дублировать код для очистки памяти возможно не очень хорошо, но флаг может помочь.

Comment on lines 6 to 9




Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump

return stack->head == NULL;
}

void delete(Stack* stack)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В наших условиях не лучшее название, потому что clang-format считает delete оператором из C++ :(


Stack* new(); // создание стека
void push(Stack* stack, int value); // добавляеи элемент на вершину стека
int pop(Stack* stack); // убирает из стека элемент и возвращает его
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я Вас явно просил задокументировать правила использования pop

WoWaster
WoWaster previously approved these changes Dec 22, 2025
@shannami shannami dismissed WoWaster’s stale review December 22, 2025 10:54

The merge-base changed after approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants